import allure
from page_object.roncoo_login import RoncooLogin
from page_element.el_payment_manage import payment_product, payment_manage_click
import logging
from utils.timer import sleep
from pytest_assume.plugin import assume



class RecnooPaymentManage(RoncooLogin):

    def payment_manage(self):
        # 前置条件：已登录
        self.roncoo_login()
        with allure.step(f"点击支付管理"):
            self.click(payment_manage_click)
        with allure.step(f"点击支付产品信息"):
            sleep(2)
            self.click(payment_product.payment_product_click)
        with allure.step(f"点击添加支付产品"):
            sleep(2)
            self.click(payment_product.add_product)
        with allure.step(f"输入支付产品编码"):
            self.send_keys(payment_product.product_number, 'yyds')
        with allure.step(f"输入支付产品名称"):
            self.send_keys(payment_product.product_name, '王二麻子')
        with allure.step(f"点击提交"):
            sleep(2)
            self.click(payment_product.submit_btn)
        with allure.step(f"点击支付产品页面中的设置支付方式"):
            sleep(2)
            self.click(payment_product.set_way)
        with allure.step(f"点击设置支付方式"):
            sleep(2)
            self.click(payment_product.set_way_click)
        with allure.step(f"输入支付费率"):
            self.send_keys(payment_product.payment_hl, '1')
        with allure.step(f"点击提交"):
            sleep(2)
            self.click(payment_product.set_way_submit_btn)
        with allure.step(f"点击支付产品信息"):
            sleep(2)
            self.click(payment_product.payment_product_click)
        with allure.step(f"点击上架"):
            sleep(2)
            self.click(payment_product.add_grounding)
        with allure.step(f"点击确定"):

            self.click(payment_product.sure_btn)
        # 隐式等待---断言
        self.driver.implicitly_wait(10)
        with allure.step('验证新增支付产品上架成功'):
            dy = self.text(payment_product.dy_sure)
            assume('操作成功' in dy, f"断言失败(验证失败): 期望包含'操作成功'，实际得到'{dy}'")

